package fr.emn.integration.synthese.controle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import fr.emn.integration.synthese.abstraction.Cours;
import fr.emn.integration.synthese.abstraction.Evaluation;
import fr.emn.integration.synthese.abstraction.Groupe;
import fr.emn.integration.synthese.presentation.EvalDialog;
import fr.emn.integration.synthese.presentation.GroupeDialog;

public class ControlJButtonSaveEval implements ActionListener {

	private Cours modele;
	private boolean creation;
	private EvalDialog parent;
	
	public ControlJButtonSaveEval(EvalDialog evalDialog, Cours modele,boolean creation) {
		this.modele = modele;
		this.parent = evalDialog;
		this.creation = creation;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (parent.getDate()!=null) {
			Evaluation g = new Evaluation(modele.getModuleCourante(),parent.getTypeE(), parent.getDate());
			try {
				modele.saveEvaluation(g, creation);
				parent.setVisible(false);
			} catch (SQLException e1) {
				JOptionPane.showMessageDialog(parent, "On ne peut pas!", "Erreur!",
						JOptionPane.ERROR_MESSAGE);
			}
		}
	}

}
